/**
 * 节点在画布上的位置和其他节点的关系管理类
 *
 * @class AbstractNode
 * @constructor
 * @param {Number} x
 * @param {Number} y
 * @param {Number} [id]
 */

var AbstractNode = Class.create( {

    initialize: function(x, y, id) {
        //console.log("abstract node");
        this._id = id;
        this._comments = "";
        !this._type && (this._type = "AbstractNode");
        this._graphics = this._generateGraphics(x, y);
    },

    /**
     * @method getID
     * @return {Number}
     */
    getID: function() {
        return this._id;
    },

    /**
     * @method setID
     */
    setID: function(id) {
        if (id == this._id) return;
        this._id = id;
        this._graphics.onSetID(id);
    },

    /**
     * @method _generateGraphics
     * @param {Number} x
     * @param {Number} y
     * @return {AbstractNodeVisuals}
     * @private
     */
    _generateGraphics: function(x, y) {
        return new AbstractNodeVisuals(this, x, y);
    },

    /**
     * @method getGraphics
     * @return {AbstractNodeVisuals}
     */
    getGraphics: function() {
        return this._graphics;
    },

    /**
     * @method getX
     * @return {Number}
     */
    getX: function() {
        return this.getGraphics().getX();
    },

    /**
     * @method getY
     * @return {Number}
     */
    getY: function() {
        return this.getGraphics().getY();
    },

    /**
     * @method setPos
     * @param {Number} x
     * @param {Number} y
     * @param {Boolean} [animate]
     * @param {Function} [callback]
     */
    setPos: function(x,y, animate, callback) {
        this.getGraphics().setPos(x, y, animate, callback);
    },

    /**
     * @method getType
     * @return {String}
     */
    getType: function() {
        return this._type;
    },

    /**
     * @method remove
     * @param [skipConfirmation=false] {Boolean} 
     */
    remove: function() {
        this.getGraphics().remove();
    },

    /**
     * @method getComments
     * @return {String}
     */
    getComments: function() {
        return this._comments;
    },

    /**
     * @method setComments
     * @param comment
     */
    setComments: function(comment) {
        this._comments = comment;
    },

    /**
     * @method addCancer
     * @param cancertype
     */
    addCancerTypes: function(cancertypes) {
        this._addcancertypes = cancertypes;
    },

    /**
     * @method getProperties
     * @return {Object} in the form
     *
     */
    getProperties: function() {
        var info = {};
        if (this.getComments() != "")
            info['comments'] = this.getComments();
        return info;;
    },

    /**
     * @method assignProperties
     * @param properties Object
     * @return {Boolean} 
     */
    assignProperties: function(properties) {
        if (properties.hasOwnProperty("comments") && this.getComments() != properties.comments) {
            this.setComments(properties.comments);
        }
        return true;
    },

    /**
     * @method onWidgetHide
     */
    onWidgetHide: function() {
        this.getGraphics().getHoverBox() && this.getGraphics().getHoverBox().onWidgetHide();
    },

    onWidgetShow: function() {
        this.getGraphics().getHoverBox() && this.getGraphics().getHoverBox().onWidgetShow();
    }
});


var ChildlessBehavior = {
    /**
     * @method getChildlessStatus
     * @return {Null|String} null, childless or infertile
     */
    getChildlessStatus: function() {
        return this._childlessStatus;
    },

    /**
     * @method isValidChildlessStatus
     * @return {Boolean}
     */
    isValidChildlessStatus: function(status) {
        return ((status == 'infertile' || status == 'childless'));
    },

    /**
     *
     * @method getChildlessReason
     * @return {String}
     */
    getChildlessReason: function() {
        return this._childlessReason;
    },

    /**
     * @method setChildlessReason
     * @param {String} reason 
     */
    setChildlessReason: function(reason) {
        if(this.getChildlessStatus() == null)
            reson = "";
        this._childlessReason = reason;
        this.getGraphics().updateChildlessStatusLabel();
    }
};
